<template>
	<view class="content">
		
	
		
		<view class="input-group">
			<view class="input-row border">
				<text class="title">简介：</text>
				
				<m-input type="text" focus clearable v-model="title" placeholder="请输入简介"></m-input>
			</view>
			<view class="input-row border">
				<text class="title">企业名称：</text>
				<m-input type="text" focus clearable v-model="author" placeholder="请输入企业名称"></m-input>
			</view>
			
			<view class="input-row border">
				<text class="title">正文：</text>
				<text class="title">{{rich =='undefined' ?  '未编辑': '已编辑'}}</text>
				<button type="primary" class="primary" style="padding-left: 7px;padding-right: 7px;font-size: 16px;line-height: 1.8;margin-top: auto;margin-bottom: auto;" @tap="goIndex">编辑正文</button>
			</view>
			</view>
		<view class="btn-row">
			<button type="primary" class="primary" @tap="updata">发布招聘信息</button>
		</view>
	</view>
</template>

<script>
	
	import mInput from '../../components/m-input.vue';
	import uniCard from '@/components/uni-card/uni-card.vue';
	export default {
		components: {
			mInput,
			uniCard
		},
		data() {

			return {
				title:'',
				author:'',
				uid:uni.getStorageSync('setUserData').id,
				rich:'',
				 array: ['法律法规', '检测标准', '前沿发展'],
				index: 0,
			}
		},
		//页面加载前给初始参数赋值，不能直接使用缓存参数
		onLoad(e) {
			
			let rich = decodeURIComponent(e.rich)
			console.log(rich);
			this.rich = rich;
			this.author= uni.getStorageSync('setUserData').name;
			
		},
		methods: {
		 bindPickerChange: function(e) {
			
				this.index = e.target.value
			},
			goIndex(){
				uni.navigateTo({
					url:'../index/index?fid=2'
				})
			},
			updata() {
				/**
				 * 客户端对账号信息进行一些必要的校验。
				 * 实际开发中，根据业务需要进行处理，这里仅做示例。
				 */
				// if (this.phone1.length < 11) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: '手机号最短为 11个字符'
				// 	});
				// 	return;
				// }
				var tem = '';
				var reg = /<img.+?src=('|")?([^'"]+)('|")?(?:\s+|>)/gim;
					    var imgsrcArr = [];  
					    while (tem = reg.exec(this.rich)) {  
					        imgsrcArr.push(tem[2]);  
					    }  
				
				
				uni.request({
					url: 'http://wd1900144.pro.wdcase.com/carApi/news.php',
					method: 'GET',
					data: {
						act:'add',
						title:this.title,
						author:this.author,
						content:this.rich,
						img:imgsrcArr[0],
						cid:4
					},
					success: res => {	
							console.log(res);
						 //  uni.setStorageSync('order', {
							// num:res.data.res
						 //  })
						uni.showToast({
							title:res.data.msg
						});
						if(res.data.error==0)
						{	uni.reLaunch({
								url:'../my/my'
							})}
						
						// 	uni.navigateTo({
						// 			url:'../my/my'
						// 	})
							
						
					
					},
					fail: () => {},
					complete: () => {}
				});
				
				
			}
		}
	}
</script>

<style>
body{
	background-color: #efeff4;
}
  .input-row .title {
	  width:170upx;
  }
 .content {
 	display: flex;
 	flex: 1;
 	flex-direction: column;
 	background-color: #efeff4;
 	padding: 10px;
 }
 .input-group {
 	background-color: #ffffff;
 	margin-top: 20px;
 	position: relative;
 }
 
 .input-group::before {
 	position: absolute;
 	right: 0;
 	top: 0;
 	left: 0;
 	height: 1px;
 	content: '';
 	-webkit-transform: scaleY(.5);
 	transform: scaleY(.5);
 	background-color: #c8c7cc;
 }
 
 .input-group::after {
 	position: absolute;
 	right: 0;
 	bottom: 0;
 	left: 0;
 	height: 1px;
 	content: '';
 	-webkit-transform: scaleY(.5);
 	transform: scaleY(.5);
 	background-color: #c8c7cc;
 }
 
 .input-row {
 	display: flex;
 	flex-direction: row;
 	position: relative;
 	font-size: 18px;
 	line-height: 40px;
 }
 
 .input-row .title {
 	width: 100px;
 	padding-left: 15px;
 }
 
 .input-row.border::after {
 	position: absolute;
 	right: 0;
 	bottom: 0;
 	left: 8px;
 	height: 1px;
 	content: '';
 	-webkit-transform: scaleY(.5);
 	transform: scaleY(.5);
 	background-color: #c8c7cc;
 }
 .btn-row{
	 margin-top: 100px;
 }
</style>
